package com.suven.framework.core.redis.factory;


import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.stereotype.Component;

@Component
public class RedisConnectionStrategyFactory extends AbstractRedisConnection implements RedisConnectionStrategy{



    public RedisConnectionStrategyFactory(RedisConfigurationSetting redisConfig) {
       super(redisConfig);
    }

    /**
     *
     * @return
     */
    @Override
    public RedisConnectionFactory createConnectionFactory() {
        RedisConnectionEnum redisEnum = RedisConnectionEnum.getEnum(getRedisConfig().getClient().getModel());
        RedisConnectionStrategy strategy = null;
        switch (redisEnum){
            case REDIS_STANDALONE_STRATEGY:{
                strategy = new RedisConnectionInStandalone(redisConfig);
                break;
            }
            case REDIS_SENTINEL_STRATEGY:{
                strategy = new RedisConnectionInSentinel(redisConfig);
                break;
            }
            case REDIS_MASTER_SLAVE_STRATEGY:{
                strategy = new RedisConnectionInMasterSlave(redisConfig);
                break;
            } case REDIS_CLUSTER_STRATEGY:{
                strategy = new RedisConnectionInCluster(redisConfig);
                break;
            }
            case REDIS_CLUSTER_GROUP_STRATEGY:{
                strategy = new RedisConnectionInCluster(redisConfig);
                break;
            } default:{
                strategy = new RedisConnectionInStandalone(redisConfig);
            }
        }
        RedisConnectionFactory factory = strategy.createConnectionFactory();
        return factory;
    }


}